#! /usr/bin/env python
#coding=utf-8

def costtime(func):
    """
    装饰器函数，以aop的方式记录函数执行时间
    """
    def newFunc(*args, **args2):
        import time  
        t0 = time.time()  
        print "@%s, {%s} start" % (time.strftime("%X", time.localtime()), func.__name__)  
        back = func(*args, **args2)  
        print "@%s, {%s} end" % (time.strftime("%X", time.localtime()), func.__name__)  
        print "@%.3fs taken for {%s}" % (time.time() - t0, func.__name__)  
        return back  
    return newFunc  

import urllib2,datetime

@costtime
def m1():
    dangdang=r"http://search.dangdang.com/book/search_pub.php?key=%B6%C5%C0%AD%C0%AD&catalog=01&SearchFromTop=1"
#    start=datetime.datetime.now()
    html=urllib2.urlopen(dangdang).read()
#    end=datetime.datetime.now()
    #print html
#    print (end-start).seconds


import httplib
@costtime
def m2():
    conn=httplib.HTTPConnection("search.dangdang.com")
    conn.request("GET","/book/search_pub.php?key=%B6%C5%C0%AD%C0%AD&catalog=01&SearchFromTop=1")
    html=conn.getresponse().read()
    
if __name__=='__main__':
    m2()
    m1()